package com.vincent.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.MapPropertySource;
import org.springframework.data.redis.connection.RedisClusterConfiguration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by vincent on 2018/7/14.
 */
@Configuration
public class RedisConfig {

    @Value("${spring.redis.cluster.nodes}")
    private String nodes;

    @Value("${spring.redis.cluster.max-redirects}")
    private String redirects;

    @Bean
    public RedisConnectionFactory connectionFactory(){
        Map<String,Object> config = new HashMap<>();
        config.put("spring.redis.cluster.nodes", nodes);
        config.put("spring.redis.cluster.max-redirects", redirects);
        return new LettuceConnectionFactory(new RedisClusterConfiguration(new MapPropertySource("redisConfig",config)));
    }

}
